<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script  src="https://cdn.bootcdn.net/ajax/libs/axios/1.2.1/axios.js"></script>
</head>
<body>
    <script>
        
       

        //请求拦截器 从后往前执行
        axios.interceptors.request.use(config=>{
            console.log("请求拦截器1");
            console.log(config.headers.a);
            return config;
        });

        axios.interceptors.request.use(config=>{
            console.log("请求拦截器2");
            config.headers = {
                a:12
            }
            return config;
        });

        // 从前往后执行
        axios.interceptors.response.use(res=>{
            console.log("响应拦截器1");
            return res.data;
        },(rea)=>{
            // 响应失败时执行的函数
            // 错误处理
            console.log("失败了",rea);

            // return rea.message;
            throw rea.message;
        });

        axios.interceptors.response.use(res=>{
            console.log("响应拦截器2");
            console.log(res);
            return res[0].name;
        },(rea)=>{
            console.log(rea);
        });

        axios('http://localhost:3001/movies').then(val=>{
            console.log(val);
        })



    </script>
</body>
</html>